package com.mapbar.pay.util;

import com.mapbar.logic.cache.CacheFactory;
import org.apache.log4j.Logger;

/**
 * @date  2010-3-4  17:09:19
 * @author fengbj
 */
public class CacheUtil {

    public static Logger  logger = Logger.getLogger(CacheUtil.class);//日志对象
    private static com.mapbar.logic.cache.Cache cache = CacheFactory.getCache();

    /**
     * 放入缓存,有效期只对memcached服务有效
     *
     */
    public static synchronized boolean set(String key, Object obj) {
        if(key == null || obj == null){
            logger.error("向缓存存入对象失败：key =[" + key +"]" + ", obj = [" + obj +"]");
            return false;
        }else{
            logger.info("向缓存存入对象：" + obj.toString());
            return cache.set(key, obj, ProjectUtil.USER_INFO_TIME);
        }
    }

    /**
     * 删除
     */
    public static synchronized boolean remove(String key) {
        if(key == null){
            logger.error("不可从缓存删除key为null的对象");
            return false;
        }else{
            logger.info("删除对象 Key = " + key);
             return cache.delete(key);
        }
       
    }

    /**
     * 得到
     */
    public static synchronized  Object get(String key) {
        if(key != null){
            logger.info("从缓存取出对象：key = " + key);
            return cache.get(key);
        }
        else{
            return key;
        }
    }

}
